home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c,comp.lang.c.moderated,hp.unix,comp.sys.hp.apps,comp.sys.hp.hpux
- Subject: Re: C coding problem
- Date: 3 Apr 1996 19:13:07 -0600
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4jv7n3$d8o@solutions.solon.com>
- References: <4ianbf$h86@solutions.solon.com> <4io1io$no4@solutions.solon.com> <4j06na$808@solutions.solon.com> <4jttan$3gf@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <4jttan$3gf@solutions.solon.com>,
- Niall Smart <nsmart@indigo.ie> wrote:
- >
- >>: I recently wrote a loop that went like this:
- >
- >>: while (p < end_p)
- >>: ++*p++;
- >
- >>: Maybe some will find it a counter-example; I think it's good
- >>: code that embodies the way C is designed to work. Arrays are
- >>: second rate objects in C. Use pointers.
- >
- >That code scores negative for maintainability, why use arcane
- >features of the language that can be replaced with more readable code?
- >If you read any of the books on writing good code you will find
- >hundreds of reasons to avoid code like that. The execution time you
- >*might* be saving is offset many times by the time it takes a
-
- Actually you don't really save any execution time compared to using an array
- index. Any decent optimizer will turn an array indexing loop into pointer
- manipulation. Inserting extra parentheses also won't affect the execution time
- either: ++(*(p++))
-
- >maintainer to figure it out.
-
- If the maintainer is worth his or her paycheck, he or she will know what it
- does by mentally inserting those parentheses: clearly, the thing that p
- currently points to is incremented, and p is incremented as well. I wouldn't
- hire a C maintainer who didn't know the basic precedence rules of the C
- language sufficiently well to know what ++*p++ does, or perhaps I'd arrange for
- mandatory comp.lang.c, ISO 9899, K&R and H&S reading if the person otherwise
- came with great references and credentials!
-
- Which is not to say that we should purposely write maintainer-hostile code!
- This is better for testing the maintainer in an interview more than anything
- else.
- --
-